package servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import business.BusinessComment;
import business.BusinessUser;
import business.IBusinessComent;
import business.IBusinessUser;
import domain.IComment;
import domain.IUser;

/**
 * Servlet implementation class ManagerComment
 */
@WebServlet("/ManagerComment")
public class ManagerComment extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ManagerComment() {
        super();
        
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		showComment(request,response);
	}
	
	private void showComment(HttpServletRequest request, HttpServletResponse response) throws IOException{
		
		PrintWriter out = response.getWriter();
		IBusinessComent businessComment = new BusinessComment();
		IBusinessUser businessUser = new BusinessUser();
		
		
		List<IComment> comments = businessComment.getAllComments();
		out.println("Lista de comentarios" + "<br>");
		
		for(IComment comment : comments){
			IUser user = businessUser.getUserByLogin(comment.getUserCommentarieID());
			out.println(user.getLogin() + "   " + "dice: "+ "    " + comment.getCommentarie() + "<br>");
		}
		
	}

}
